package com.googlecode.jasperlib.internal;

import com.googlecode.jasperlib.ClassLoaderInterface;

import java.net.URL;
import java.util.Enumeration;
import java.io.IOException;
import java.io.InputStream;

public class ClassLoaderInterfaceAdapter extends ClassLoader {
    protected final ClassLoader classLoader;
    protected final ClassLoaderInterface classLoaderInterface;

    public ClassLoaderInterfaceAdapter(ClassLoader classLoader, ClassLoaderInterface classLoaderInterface) {
        super(classLoader);
        this.classLoader = classLoader;
        this.classLoaderInterface = classLoaderInterface;
    }

    public Class<?> loadClass(String name) throws ClassNotFoundException {
        try {
            return classLoaderInterface.loadClass(name);
        } catch (Throwable t) {
            //ok
        }

        return super.loadClass(name);
    }

    public URL getResource(String name) {
        try {
            return classLoaderInterface.getResource(name);
        } catch (Throwable t) {
            //ok
        }

        return super.getResource(name);
    }

    public Enumeration<URL> getResources(String name) throws IOException {
       try {
            return classLoaderInterface.getResources(name);
        } catch (Throwable t) {
            //ok
        }

        return super.getResources(name);
    }

    public InputStream getResourceAsStream(String name)  {
         try {
            return classLoaderInterface.getResourceAsStream(name);
        } catch (Throwable t) {
            //ok
        }

        return super.getResourceAsStream(name);
    }
}
